<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
.item{
	width: 90px;
	display: inline-block;
	margin-left: 5px;
}
</style>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table style="width:100%;">
			<tr>
			    <td style="width:30%;">
			    	<span class="item">姓名(模糊)：</span>
			    	<input id="name" class="mini-textbox" emptyText="请输入姓名" style="width:160px;"/>
			    </td>
			    <td style="width:30%;">
			    	<span class="item">性别：</span>
			    	<input id="sex" showNullItem="true" nullItemText="全部" class="mini-combobox" style="width:160px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
   				 		url="dictionary_cm_key_val_view.do?typeName=CUSTOMER_SEX_TYPE" allowInput="false"/>
			    </td>
			    <td style="width:30%;">
			    	<span class="item">电话号(精确)：</span>
			    	<input id="telId" class="mini-textbox" emptyText="请输入电话号(精确)"   style="width:160px;"/>
			    </td>
			    <td style="display: inline-block;">&nbsp;</td>
			 </tr>
			 <tr>
			    <td>
			    	<span class="item">客户级别：</span>
			    	<input id="customerLevel" showNullItem="true" nullItemText="全部" class="mini-combobox" style="width:160px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
   				 		url="dictionary_cm_key_val_view.do?typeName=CUSTOMER_LEVEL_TYPE" allowInput="false"/>
			    </td>
			    <td>
			    	<span class="item">客户来源：</span>
			    	<input id="customersSource" showNullItem="true" nullItemText="全部" class="mini-combobox" style="width:160px;" textField="keyValue" valueField="keyName" emptyText="请选择..."
   				 		url="dictionary_cm_key_val_view.do?typeName=CUSTOMER_SOURCE_TYPE" allowInput="false"/>
			    </td>
			    <td>
			    	<span class="item">编号：</span>
			    	<input id="serialNum" class="mini-textbox" emptyText="请输入编号"  style="width:160px;"/>
			    </td>
			    <td style="display: inline-block;"><a class="mini-button" iconCls="icon-search" onclick="search()">查询</a></td>
			 </tr>
		</table>          
	</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td style="width:100%;">
	                <sec:authorize url='/customer_manage_add.do'>
				    <a class="mini-button"  onclick="addCustomer()" iconCls="icon-add">新增客户</a>
					</sec:authorize> 
					<sec:authorize url='/customer_add_black.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="setBlack()">加入黑名单</a>
	                </sec:authorize>
	                <sec:authorize url='/customer_out_black.do'>
	                <a class="mini-button" iconCls="icon-downgrade" onclick="outBlack()">移除黑名单</a>
	                </sec:authorize>
	                <sec:authorize url='/customer_details_current_export.do'>
	                <a class="mini-button" iconCls="icon-download" onclick="exportCurrentData()">导出当前</a>
	                </sec:authorize>
	                <sec:authorize url='/customer_details_export.do'>
		            <a class="mini-button" iconCls="icon-download" onclick="exportData()">导出全部</a>
		            </sec:authorize>
		            <sec:authorize url='/import_customer_view.do'>
	                <a class="mini-button" iconCls="icon-upload" onclick="importCustomer()">导入客户</a>
	                </sec:authorize>
	                <a class="mini-button" iconCls="icon-upload" onclick="importToCall()">导入到任务</a>
	                <sec:authorize url='/customer_import_download.do'>
	                <a class="mini-button" iconCls="icon-download" href="customer_import_download.do">下载导入模版</a>
	                </sec:authorize>
	                <a class="mini-button" iconCls="icon-edit" onclick="setBackCount">设置允许客户退单、网退数量</a>
	            </td>
	        </tr>
	    </table>           
	</div>
	<!-- 设置允许客户网退、退单数量弹窗 -->
	<div id="win1" class="mini-window" showModal="false" allowDrag="false" showHeader="false" title="呼出" style="width: 200px;height: 110px;">
	    <input labelField="true" label="数量：" labelStyle="width: 40px;" class="mini-textbox" style="width:170px;margin-top: 7px;margin-left: 5px;" required="true" id="back_count" /> 
		<div style="text-align:center;padding-bottom: 5px;margin-top: 10px;">
			<a class="mini-button" onclick="onOk" style="">确定</a>
			<a class="mini-button" onclick="onClose" style="margin-left: 30px;">关闭</a>
		</div>
	</div>
	<div class="mini-fit" >
		<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" url="customer_manage_view.do" multiSelect="true" style="width:100%;height:100%;">
			<div property="columns">
				<div type="indexcolumn"></div>
				<div type="checkcolumn" checked="false" ></div>
				<div field="serialNum" width="15%" headerAlign="center" align="center">编号</div>
				<div field="name" width="10%" headerAlign="center" align="center">姓名</div>
				<div field="sexName" width="10%" headerAlign="center" align="center">性别</div>
				<div field="contactNo" width="15%" headerAlign="center" align="center">电话号码</div>
				<div field="keyCustomersSource" width="12%" headerAlign="center" align="center">客户来源</div>
				<div field="keyCustomerLevel" width="15%" headerAlign="center" align="center">客户级别</div>
				<div field="isblackText" width="10%" headerAlign="center" align="center">黑名单用户</div>
				<div field="haveCall" width="13%" headerAlign="center" align="center">是否已生成任务</div>
				<div width="10%" headerAlign="center" align="center" renderer="onActionRenderer">详细信息</div>
			</div>
		</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();

function search() {
	var name = mini.get("name").getValue();
	var tel = mini.get("telId").getValue();
	var sex = mini.get("sex").getValue();
	var customerLevel = mini.get("customerLevel").getValue();
	var customersSource = mini.get("customersSource").getValue();
	var serialNum = mini.get("serialNum").getValue();
    grid.load({ 
    	name: name ,
    	sex: sex ,
    	contactNo: tel ,
    	customerLevel: customerLevel,
    	customersSource: customersSource,
    	serialNum: serialNum
   });
}

function onActionRenderer(e) {
	var record = e.record;
    return '<a href="javascript: customerDetail('+record._uid+')">详细信息</a> ';
}

function customerDetail(row_uid) {
	var row = grid.getRowByUID(row_uid);
	mini.open({
        url: "customer_detail_view.do",
        allowResize:false,
        title: "客户详细信息", width: 900, height: 600,
        onload: function () {
            var iframe = this.getIFrameEl();
            var data = { row: row };
            iframe.contentWindow.SetData(data);
        }
	 });
}

//导入客户
function importCustomer(){
	mini.open({
        url: "import_customer_view.do",
        allowResize:false,
        title: "批量导入客户", width: 320, height: 200,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "导入成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
        		grid.reload();
        	}
        }
	 });
}

// 导入到任务
function importToCall() {
	var rows = grid.getSelecteds();
	if(rows.length > 0) {
		var arr1 = new Array();
		var arr2 = new Array();
		
		for(var i=0; i<rows.length; i++) {
			if(!rows[i].callId && rows[i].contactNo) {
				arr1.push(rows[i].id);
				arr2.push(rows[i].contactNo);
			}
		}
		var cIds = arr1.join(",");
		var contactNos = arr2.join(",");
		if(cIds.length > 0 && contactNos.length > 0) {
			$.post("customer_import_to_call.do", {id: cIds, contactNo: contactNos}, function(data) {
				if(data.success) {
					mini.showMessageBox({
			               title: "提示",
			               showModal:false,
			               iconCls: "mini-messagebox-info",
			               message: "已导入到任务（无客户号码，已有话务任务的客户未导入）",
			               timeout: 3000,
			               x: 'right',
			               y: 'bottom'
		           });
					grid.reload();
				}
			}, "json");
		} else {
			mini.alert("所选客户已存在任务中！");
		}
	} else {
		mini.alert("请选择客户！");
	}
}

//导出全部
function exportData() {
	var name = mini.get("name").getValue();
	var sex = mini.get("sex").getValue();
	var customerLevel = mini.get("customerLevel").getValue();
	var customersSource = mini.get("customersSource").getValue();
	var serialNum = mini.get("serialNum").getValue();
	
	grid.load({
    	name: name ,
    	sex: sex ,
    	customerLevel: customerLevel,
    	customersSource: customersSource,
    	serialNum: serialNum
    });
	location.href="customer_details_export.do?name="+name+"&sex="+sex
			+"&customerLevel="+customerLevel+"&customersSource="+customersSource+"&serialNum="+serialNum;
}

//导出当前页数据
function exportCurrentData() {
	var data =grid.getData();
	var ids = [];
	$.each(data , function(){
        ids.push(this.id);
    });
	 var id = ids.join(',');
	 if(id){
		 location.href="customer_details_current_export.do?ids=" +id;
	 }
}

//加入黑名单
function setBlack(){
	var rows = grid.getSelecteds();
    var arr = new Array();
    $.each(rows,function(i,v){
    	arr.push(v.id);
    });
    var rids = arr.join("-");
    $.post("customer_add_black.do",{ids:rids},function(data){
    	mini.showMessageBox({
               title: "提示",
               showModal:false,
               iconCls: "mini-messagebox-info",
               message: "已加入黑名单",
               timeout: 3000,
               x: 'right',
               y: 'bottom'
           });
   		grid.reload();
    },"json");
}

//移出黑名单
function outBlack(){
	var rows = grid.getSelecteds();
    var arr = new Array();
    $.each(rows,function(i,v){
    	arr.push(v.id);
    });
    var rids = arr.join("-");
    $.post("customer_out_black.do",{ids:rids},function(data){
    	mini.showMessageBox({
	        title: "提示",
	        showModal:false,
	        iconCls: "mini-messagebox-info",
	        message: "已移出黑名单",
	        timeout: 3000,
	        x: 'right',
	        y: 'bottom'
        });
   		grid.reload();
    },"json");
}

var win = mini.get("win1");
var form1 = new mini.Form("win1");
function setBackCount(e) {
	var el=e.sender.getEl();
	win.showAtEl(el, {
	   xAlign:"left",
	   yAlign:"below"
	});
}

function onOk() {
	form1.validate();
	if(form1.isValid() == false) return;
	$.post("customer_set_back_count.do", {backCount: backCount.getValue()}, function(data) {
		mini.showMessageBox({
	        title: "提示",
	        showModal:false,
	        iconCls: "mini-messagebox-info",
	        message: "设置成功",
	        timeout: 3000,
	        x: 'right',
	        y: 'bottom'
        });
		backCount.setValue("");
		win.hide();
	}, "json");
}

var backCount = mini.get("back_count");
function onClose(){
	backCount.setValue("");
	win.hide();
}

// 打开添加客户页面
function addCustomer() {
	mini.open({
        url: "customer_manage_add.do",
        title: "新增客户", width: 800, height: 600,
        allowResize: false,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
            } else {
	        	$.post("customer_del_new.do", {id: action.customerId}, function(data) {
	        		if(!data.success) {
	        			mini.alert("数据错误，客户id不能为空");
	        		}
	        	}, "json");
            }
        }
    });
}
</script>
</body>
</html>